package com.team.mapper;

import com.team.entity.Registration;
import com.team.vo.VolunteerInfoVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RegistrationMapper {

    // 查询注册信息
    @Select("select * from registration where student_id = #{studentId} and cid = #{cid}")
    Registration getRegistration(@Param("studentId") int studentId, @Param("cid") int cid);

    // 插入注册信息
    @Insert("insert into registration(student_id, cid, priority, note) " +
            "values (#{studentId}, #{cid}, #{priority}, #{note})")
    void insert(Registration registration1);

    // 获取当前学生的最大志愿顺序
    @Select("select max(priority) from registration where student_id = #{studentId}")
    Integer getCurPriority(int studentId);

    // 删除报名信息
    @Delete("delete from registration where student_id = #{studentId} and cid = #{cid}")
    void deleteRegistration(@Param("studentId") int studentId, @Param("cid") int cid);

    // 更新后续志愿顺序
    @Update("update registration set priority = priority - 1 " +
            "where priority > #{priority} and student_id=#{studentId}")
    void updatePriority(@Param("priority") int priority,@Param("studentId")int studentId);

    /**
     * 查询所有团队的第一志愿人数
     * @param studentId
     * @return
     */
    List<VolunteerInfoVo> getVolunteer(int studentId);

    /**
     * 查询学生的报名信息
     * @param studentId
     * @return
     */
    @Select("select * from registration where student_id=#{studentsId}")
    List<Registration> getRegistrations(int studentId);

    /**
     * 修改某个报名信息的志愿
     * @param rid
     * @param newPriority
     */
    @Update("update registration set priority=#{newPriority} where rid=#{rid}")
    void updatePriority2(@Param("rid") int rid,@Param("newPriority") int newPriority);

    /**
     * 获得某学生的第一志愿报名信息
     * @param studentId
     * @return
     */
    @Select("select * from registration where priority=1 and student_id=#{studentId} limit 1")
    Registration getFirstRegis(int studentId);
}
